package leetcode.dynamic;

public class Lc152 {

    public static int maxProduct(int[] nums) {

        double ans = Integer.MIN_VALUE, min = 1.0, max = 1.0;

        for (int i = 0; i < nums.length; i++) {
            double minTmp = min;
            min = Math.min(min * nums[i], Math.min(max * nums[i], nums[i]));
            max = Math.max(max * nums[i], Math.max(minTmp * nums[i], nums[i]));
            ans = Math.max(ans, max);
        }
        return (int)ans;
    }

    public static void main(String[] args) {
        int[] n = {-2};
        System.out.println(maxProduct(n));
        System.out.println(Double.MIN_EXPONENT);
        System.out.println(Double.MIN_VALUE);
        System.out.println(Double.MIN_NORMAL);
    }

}
